const Sequelize = require('sequelize');
const { mysql } = require('../config')

const sequelize = new Sequelize(mysql.libName, mysql.user, mysql.password, {
    host: mysql.host,
    dialect: 'mysql',
    port: mysql.port,
    dialectOptions: {
        connectTimeout: 30000
    },
    pool: {
        max: 50, // 增加最大连接数
        min: 10, // 增加最小连接数
        acquire: 30000,
        idle: 10000,
        evict: 10000 // 自动移除闲置连接
    }
});

try {
    sequelize.authenticate();
    console.log('数据库连接成功！');
} catch (error) {
    console.error('数据库连接失败：', error);
}

module.exports = sequelize